<template>
	<view>
		<view class="plr30 pt30">
			<block v-for="item in loadList" :key="item.id">
				<!-- 换电 start -->
				<view class="flex_a mb30 p30 bf border-r1"
					@click="routerLink({ path: '/pages/user/myOrder/rentEleDetail', query: { orderNo: item.orderNo } })">
					<view class="w140 w130">
						<image src="/static/hd_img.png" mode="widthFix"></image>
					</view>
					<view class="flex1 plr20">
						<!-- <view class="">订单号：{{ item.orderNo }}</view> -->
						<view class="lh50 ft26">电池编号：{{ item.newBatteryNo || '--' }}</view>
						<view class="c6">
							有效期：
							<text class="ft24">{{ item.startTime||''  }} 至 {{ item.mealTime ||'' }}</text>
						</view>
					</view>
					<view class="tae whn" style="max-width: 120upx;"
						:class="item.status == 0 ? 'warning' : item.status == 1 ? 'green' : item.status == 2 ? 'danger' :item.status == 3 ? 'warning' : ''">
						{{ item.status == 0 ? '进行中' : item.status == 1 ? '已完成' : item.status == 2 ? '已逾期' : item.status == 3 ? '已取消' : '--' }}
					</view>
				</view>
				<!-- 换电 end -->
			</block>
			<view class="flex_aj column ptb20" v-if="!loginUser|| showTime && loadList.length == 0 ">
				<view class="c9 pt20">您还没有相关订单~</view>
				<view v-if="!loginUser" style="margin-top: 30rpx;">
					<button class="btn-box" open-type="getAuthorize" scope="userInfo"
						@getAuthorize="thirdLogin">去登录查看</button>
				</view>
			</view>
			<uni-load-more v-if="showTime && loadList.length > 0" :status="loadMoreText" color="#999"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import loadMore from '@/mixins/loadMore'
	import {
		exchangeOrder
	} from '@/api/user.js'
	export default {
		name: 'myOrder',
		mixins: [loadMore],
		data() {
			return {
				showTime: false,
				loginUser: '',
			}
		},
		onLoad(e) {
			// 换电订单
			this.page == 1
			this.loadList = []

		},
		onShow() {
			this.loginUser = this.$store.state.user.token || ''
			if (this.loginUser) {
				this.exchangeOrder()
			}
		},
		onHide() {},
		computed: {
			isLogin() {
				return this.$store.state.user.isLogin
			}
		},
		methods: {
			// 换电订单
			async exchangeOrder() {
				const res = await exchangeOrder({
					pageNum: this.page,
					pageSize: this.limit
				})
				this.showTime = true
				this.loadList = this.page == 1 ? res.rows : [...this.loadList, ...res.rows]
				console.log('23432', this.loadList);
				this.pageLength = res.rows.length
				this.loadMoreText = res.rows.length < this.limit ? 'noMore' : 'more'
			},
		}
	}
</script>

<style scoped lang="scss">
	.tab_w {
		position: fixed;
		top: 16upx;
		left: 30upx;
		width: 690upx;
		height: 100upx;
		padding: 10upx 14upx;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 50upx;
		overflow: hidden;
		box-shadow: 0px 4px 18px 0px rgba(50, 130, 255, 0.24);
	}

	.btn-box {
		color: #fff;
		background-color: #3282FF;
		border-radius: 50rpx;
		padding: 0 15px;
	}
</style>